package Structural.Composite.demo1;

public class CompositeDemo1 {
	public static void main(String[] args) {
		BranchNode root = new BranchNode("root");

		BranchNode c1 = new BranchNode("c1");
		BranchNode c2 = new BranchNode("c2");
		root.add(c1);
		root.add(c2);
		c1.add(new LeafNode("c11"));
		c1.add(new LeafNode("c12"));
		c2.add(new LeafNode("c21"));

		printTree(root, 0);
	}


	static void printTree(Node node, int depth) {
		for (int i = 0; i < depth; i++) {
			if (i == 0) System.out.print("|");
			System.out.print("_");
		}
		node.printName();

		if (node instanceof BranchNode) {
			BranchNode node1 = (BranchNode) node;
			for (Node node2 : node1.nodes) {
				printTree(node2, depth + 1);
			}
		}
	}
}
